// You can see all the config in `./configs`.
const  buildPlugins = require('./configs/plugin');
let webpackConfig;
const fs = require('fs');
const path = require('path');
// var ip = require('ip').address()

function doInitHost(env) {
    let node_env_host = '';
    console.log(env);
    console.log(env.NODE_ENV);
    switch (env.NODE_ENV) {
        case 'prod':
        case 'production':
            // node_env_host = '118.89.16.63';
            node_env_host = 'http://192.168.1.191:5000';
            break;
        case 'release':
            node_env_host = '';
            break;

        case 'test':
        case 'testing':
        case 'dev':
        case 'development':
        default:
            node_env_host = 'http://192.168.1.191:5000';
    }
    let ip = node_env_host;
    console.log("host",ip);
    fs.writeFileSync(path.resolve('src/util/host.js'), 'export const host =  \'' + ip + '\';');
}
module.exports = env => {
  switch (env.NODE_ENV) {
    case 'prod':
    case 'production':
      webpackConfig = require('./configs/webpack.prod.conf');
      break;
    case 'test':
    case 'testing':
      webpackConfig = require('./configs/webpack.test.conf');
      break;
    case 'plugin':
      buildPlugins();
    case 'common':
      webpackConfig = require('./configs/webpack.common.conf');
      break;
    case 'release':
      webpackConfig = require('./configs/webpack.release.conf');
      break;
    case 'dev':
    case 'development':
    default:
      webpackConfig = require('./configs/webpack.dev.conf');
  }
    doInitHost(env);
  return webpackConfig;
}
